home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Golden Games / Amiga CD-Sensation - Ausgabe 2 - Golden Games (1996)(GTI - Schatztruhe)(DE)[!].iso / Brain Activity / Tetris / TestImages.c < prev    next >
C/C++ Source or Header  |  1992-11-18  |  7KB  |  216 lines

  1. /*
  2. Copyright (c) 1992, Trevor Smigiel.  All rights reserved.
  3.  
  4. (I hope Commodore doesn't mind that I borrowed their copyright notice.)
  5.  
  6. The source and executable code of this program may only be distributed in free
  7. electronic form, via bulletin board or as part of a fully non-commercial and
  8. freely redistributable diskette.  Both the source and executable code (including
  9. comments) must be included, without modification, in any copy.  This example may
  10. not be published in printed form or distributed with any commercial product.
  11.  
  12. This program is provided "as-is" and is subject to change; no warranties are
  13. made.  All use is at your own risk.  No liability or responsibility is assumed.
  14.  
  15. */
  16.  
  17. #include <exec/types.h>
  18. #include <intuition/intuition.h>
  19. #include <intuition/gadgetclass.h>
  20. #include <intuition/imageclass.h>
  21. #include <intuition/icclass.h>
  22. #include <clib/macros.h>
  23. #include <dos/rdargs.h>
  24. #include <stdio.h>
  25. /* comment for includesym.ced, puts protos after comment */
  26. #include <proto/exec.h>
  27. #include <proto/intuition.h>
  28. #include <proto/dos.h>
  29. #include <proto/graphics.h>
  30.  
  31. #include "Tetris.h"
  32. #include "TetrisImages_protos.h"
  33.  
  34.  
  35. LONG            XSize = 16;
  36. LONG            YSize = 16;
  37. LONG            Depth = 2;
  38. char            Template[] = "DEPTH/N,XSIZE/N,YSIZE/N";
  39. LONG            Args[] = {0, 0, 0};
  40.  
  41. struct Screen  *Screen;
  42. struct DrawInfo *DInfo;
  43. struct Gadget  *Gadgets = NULL;
  44.  
  45. void
  46. FreeGList(struct Gadget *Gads, int i)
  47. {
  48.     struct Gadget  *g;
  49.     while (i) {
  50.         g = Gads;
  51.         Gads = Gads->NextGadget;
  52.         if (g->GadgetRender)
  53.             DisposeObject(g->GadgetRender);
  54.         DisposeObject(g);
  55.         i--;
  56.     }
  57. }
  58.  
  59. LONG map[4] = {GA_ID, ICSPECIAL_CODE, TAG_END, 0};
  60.  
  61. struct Window  *
  62. waiting_window(void)
  63. {
  64.     struct Window  *W = NULL;
  65.     struct Gadget  *g1, *g2;
  66.     struct Image   *i1, *i2;
  67.     int w, h;
  68.  
  69.     g1 = NewObject(NULL, "frbuttonclass",
  70.         GA_ID, 1,
  71.         GA_Previous, &Gadgets,
  72.         GA_Left, Screen->WBorLeft + 4,
  73.         GA_Top, Screen->WBorTop + Screen->Font->ta_YSize + 4,
  74.         GA_Text, "Abort",
  75.         GA_Image, i1 = NewObject(NULL, "frameiclass", TAG_END),
  76.         GA_DrawInfo, DInfo,
  77.         GA_RelVerify, TRUE,
  78.         //ICA_TARGET, ICTARGET_IDCMP,
  79.         //ICA_MAP, map,
  80.         TAG_END
  81.         );
  82.     if (g1) {
  83.         g2 = NewObject(NULL, "frbuttonclass",
  84.             GA_ID, 2,
  85.             GA_Previous, &Gadgets,
  86.             GA_Left, Screen->WBorLeft + 4,
  87.             GA_Top, Screen->WBorTop + Screen->Font->ta_YSize * 2 + 10,
  88.             GA_Text, "Play",
  89.             GA_Image, i2 = NewObject(NULL, "frameiclass", TAG_END),
  90.             GA_DrawInfo, DInfo,
  91.             GA_RelVerify, TRUE,
  92.             //ICA_TARGET, ICTARGET_IDCMP,
  93.             //ICA_MAP, map,
  94.             TAG_END
  95.         );
  96.         if (g2) {
  97.             struct IBox dud1;//, dud2;
  98.  
  99.             //DoMethod((Object *)i1, IM_FRAMEBOX, &g1->LeftEdge, &dud1, DInfo, 0);
  100.             //dud1.Width  += 10; //Screen->Font->ta_YSize * 7;
  101.             //dud1.Height += 2; //Screen->Font->ta_YSize + 24;
  102.             //DoMethod((Object *)i1, IM_FRAMEBOX, &g1->LeftEdge, &dud1, DInfo, FRAMEF_SPECIFY);
  103.             //printf("%d %d %d %d -- ", i1->LeftEdge, i1->TopEdge, i1->Width, i1->Height);
  104.  
  105.             //DoMethod((Object *)i2, IM_FRAMEBOX, &g2->LeftEdge, &dud2, DInfo, 0);
  106.             //dud2.Width  += 10; //Screen->Font->ta_YSize * 7;
  107.             //dud2.Height += 2; //Screen->Font->ta_YSize + 24;
  108.             //DoMethod((Object *)i2, IM_FRAMEBOX, &g2->LeftEdge, &dud2, DInfo, FRAMEF_SPECIFY);
  109.             //printf("%d %d %d %d\n", i2->LeftEdge, i2->TopEdge, i2->Width, i2->Height);
  110.  
  111.             dud1.Width = MAX(g1->Width, g2->Width) * 2;
  112.             dud1.Height = MAX(g1->Height, g2->Height);
  113.  
  114.             SetAttrs(g1, GA_Width, dud1.Width, GA_Height, dud1.Height, TAG_END);
  115.             SetAttrs(g2, GA_Top, g1->TopEdge + g1->Height + 2, GA_Width, dud1.Width, GA_Height, dud1.Height, TAG_END);
  116.  
  117.             w = Screen->WBorLeft + Screen->WBorRight + MAX(g1->Width, XSize * 4) + 8;
  118.             h = Screen->WBorTop + Screen->WBorBottom + Screen->Font->ta_YSize + MAX(g1->Height + g2->Height, YSize * 4) + 10;
  119.             W = OpenWindowTags(NULL,
  120.                 WA_Title, "Waiting for players",
  121.                 WA_ScreenTitle, "Tetris",
  122.                 WA_Left, (Screen->Width - w) / 2,
  123.                 WA_Top, (Screen->Height - h) / 2,
  124.                 WA_Width, w,
  125.                 WA_Height, h,
  126.                 WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE,
  127.                 WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE | IDCMP_RAWKEY | IDCMP_GADGETUP,
  128.                 TAG_END
  129.             );
  130.             if (W) {
  131.                 AddGList(W, Gadgets, 2, 2, NULL);
  132.                 RefreshGList(Gadgets, W, NULL, 2);
  133.                 W->UserData = (char *) 1;
  134.                 return W;
  135.             }
  136.             DisposeObject(g2);
  137.         }
  138.         DisposeObject(g1);
  139.     }
  140.     return NULL;
  141. }
  142.  
  143. int
  144. main(void)
  145. {
  146.     struct RDArgs  *RDArgs;
  147.     struct Window  *w;
  148.     struct IntuiMessage *msg;
  149.     struct BitMap  *bm = &TBitMaps[0];
  150.     int             which = 0,
  151.                     done = 0;
  152.     RDArgs = ReadArgs(Template, Args, NULL);
  153.     if (RDArgs) {
  154.         if (Args[0]) Depth = *(LONG *) Args[0];
  155.         if (Args[1]) XSize = *(LONG *) Args[1];
  156.         if (Args[2]) YSize = *(LONG *) Args[2];
  157.         if (InitTetrisImages(Depth, XSize, YSize)) {
  158.             Screen = LockPubScreen(NULL);
  159.             if (Screen) {
  160.                 w = NULL;
  161.                 DInfo = GetScreenDrawInfo(Screen);
  162.                 if (DInfo) {
  163.                     w = waiting_window();
  164.                     /*
  165.                      * w = OpenWindowTags(NULL, WA_Left, 200, WA_Top, 50,
  166.                      * WA_Width, 40 + XSize * 4, WA_Height, 40 + YSize *
  167.                      * 4, WA_Flags, WFLG_ACTIVATE | WFLG_CLOSEGADGET |
  168.                      * WFLG_DRAGBAR | WFLG_DEPTHGADGET, WA_IDCMP,
  169.                      * IDCMP_CLOSEWINDOW | IDCMP_RAWKEY, TAG_END );
  170.                      */
  171.                     if (w) {
  172.                         BltBitMapRastPort(bm, 0, 0, w->RPort, w->BorderLeft + 3, w->BorderTop + 3, TSizes[which].x, TSizes[which].y, 0xee);
  173.                         while (!done) {
  174.                             WaitPort(w->UserPort);
  175.                             while (msg = (struct IntuiMessage *) GetMsg(w->UserPort)) {
  176.                                 switch (msg->Class) {
  177.                                 case IDCMP_RAWKEY:
  178.                                     if (msg->Code & IECODE_UP_PREFIX) {
  179.                                         BltBitMapRastPort(bm, 0, 0, w->RPort, w->BorderLeft + 3, w->BorderTop + 3, TSizes[which].x, TSizes[which].y, 0x22);
  180.                                         which++;
  181.                                         if (which == 20)
  182.                                             which = 0;
  183.                                         bm = &TBitMaps[which];
  184.                                         BltBitMapRastPort(bm, 0, 0, w->RPort, w->BorderLeft + 3, w->BorderTop + 3, TSizes[which].x, TSizes[which].y, 0xee);
  185.                                     }
  186.                                     break;
  187.                                 case IDCMP_IDCMPUPDATE:
  188.                                     printf("%04x\t", msg->Code);
  189.                                     printf("%04x\t", msg->Qualifier);
  190.                                     printf("%08x\t", *(ULONG *)((LONG)msg->IAddress + 4));
  191.                                     printf("%08x\t", *(ULONG *)((LONG)msg->IAddress + 8));
  192.                                     printf("%08x\n", *(ULONG *)((LONG)msg->IAddress + 12));
  193.                                     break;
  194.                                 case IDCMP_CLOSEWINDOW:
  195.                                     done = TRUE;
  196.                                     break;
  197.                                 }
  198.                                 ReplyMsg((struct Message *)msg);
  199.                             }
  200.                         }
  201.                         RemoveGList(w, Gadgets, 2);
  202.                         FreeGList(Gadgets, 2);
  203.                         CloseWindow(w);
  204.                     }
  205.                     FreeScreenDrawInfo(Screen, DInfo);
  206.                 }
  207.                 UnlockPubScreen(NULL, Screen);
  208.             }
  209.             FreeTetrisImages(Depth, XSize, YSize);
  210.         }
  211.         FreeArgs(RDArgs);
  212.     } else
  213.         PrintFault(IoErr(), "ReadArgs");
  214.     return 0;
  215. }
  216.